import torch
import torch.nn as nn
import torch.nn.functional as F


class BCEDiscLoss(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, fake, real):
        return (-torch.log(1 - torch.sigmoid(fake)) - torch.log(torch.sigmoid(real))).mean()


class HingeDiscLoss(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, fake, real):
        return (F.relu(1 + fake) + F.relu(1 - real)).mean()


class BCEGenLoss(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, fake):
        return -torch.log(torch.sigmoid(fake)).mean()


class HingeGenLoss(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, fake):
        return -fake.mean()